package chapter10_Advanced._throw;
/**
* ClassName: ThrowTest
* Package: chapter10_Advanced._throw
* Description:
 *
 * 手动抛出异常对象：throw
 *
* @Author SherryAn
* @Create 2025/7/29 11:12
*/public class ThrowTest {
    public static void main(String[] args) {
        Student s1=new Student();
        s1.regist(123);
        s1.regist(-123);


        System.out.println(s1);
    }
}
class Student{
    int id;

    public void regist(int id){
        if(id>0){
            this.id=id;
        }else {
//            System.out.println("输入的id非法");
//            手动抛出异常类的对象
            throw new RuntimeException("输入的id非法");
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                '}';
    }
}
